<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Opt</title>
<style type="text/css">
	body {background-color: white; color: black; font-family:sans-serif; font-size:medium;}
	a:link {color: #3300ff;}
	a:visited {color: #663399;}
	a:hover {color:#0099ff;}
	a:active {color: #0066cc;}
	a.button {text-decoration:none;}
	
	table.nav  {background-color: #dbddff;}
	table.body {margin-top:2ex; margin-bottom:2ex;}
	table.programlistingindent {margin-left:32px;}
	
	img { margin-bottom:0px; margin-top:0px;}
	tt {margin-left:0.5em; margin-right:0.5em; font-weight:lighter;}
	
	p {margin-top:0ex;}
	p.synopsis {margin-left:32px;}
	p.programlistingindent {margin-left:32px;}
	p.citetitle {margin-left:2em;}
	
	ul ul {list-style-type:square;}
	ul li p {margin-top:0ex; margin-bottom:.5ex; padding:0}
	ol li p {margin-top:0ex; margin-bottom:.5ex; padding:0}
	
	h1.reftitle {color:#a90000;}
	h1.reftitle {font-size:3.7ex; margin-top:0; margin-bottom:0; font-weight:bold}
	h1.title {color:black; font-size:4ex; margin-top:1ex; font-weight:bold}
	h2.title {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:3ex}
	h3.title {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:2.5ex}
	h4.title {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:2ex}
	h2 {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:2.5ex}
	h3 {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:2ex} 
	
	pre.programlisting {margin-left:32px;}
	pre.synopsis {margin-left:32px;}
	
	
	.categorytitle {margin-top:8px; padding-top:0px;}
	.categorylist {background-color: #e1e6f2;}
 	</style>
</head>
<body>
<a name="top_of_page"></a><p style="font-size:1px;"></p>
<h1 class="reftitle">Opt</h1>
<h2>Purpose</h2>
<p>Interface for solving optimization problems</p>
<h2>Syntax</h2>
<pre class="synopsis">problem = Opt('H',H,'f',f,'pF',F,'A',A,'b',b,'Ae',Ae,...)</pre>
<pre class="synopsis">problem = Opt('M',M,'q',q,'Q',Q,'Ath',Ath,'bth',bth)</pre>
<pre class="synopsis">problem = Opt(Matrices)</pre>
<pre class="synopsis">problem = Opt(constraints, objective, theta, x)</pre>
<h2>Description</h2>
<p></p>
        Encapsulates data and solutions for LP/QP/MPLP/MPQP/LCP/PLCP problems. The data can be provided
        directly, or using YALMIP format or MPT2 format.

        The following general MPQP format that is considered by <tt>Opt</tt> class:
        <p class="programlistingindent"><img src="../../../../../fig/mpt/modules/solvers/@Opt/opt29.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt29.png"></p>
        which contains <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt1.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt1.png"> optimization variables <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt2.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt2.png">, <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt3.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt3.png"> number of parameters <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt4.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt4.png">,
        <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt5.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt5.png">inequality constrains, <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt6.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt6.png"> equality constraints and constraints on the
        parameter <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt7.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt7.png">. <tt>Opt</tt> class accepts also PLCP formulation of the form        
        <p class="programlistingindent"><img src="../../../../../fig/mpt/modules/solvers/@Opt/opt30.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt30.png"></p>
        where <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt8.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt8.png"> and <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt9.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt9.png"> are the optimization variables and <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt10.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt10.png"> is the parameter. 
        
        The output format of the optimization problem depends on the input data. For instance, 
        non-parametric LCP can be created by providing <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt11.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt11.png">, <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt12.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt12.png"> data and the parametric LPC
        by supplying <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt13.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt13.png">, <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt14.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt14.png">, and <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt15.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt15.png">. 
        
        At the time of construction, the problem data are validated and checked for proper dimensions.
        For all the methods involved in <tt>Opt</tt> class see <tt>methods('Opt')</tt>.
        
        
      
                
	<h2>Input Arguments</h2>
<table cellspacing="0" class="body" cellpadding="4" border="0" width="100%">
<colgroup>
<col width="31%">
<col width="69%">
</colgroup>
<tbody>
<tr valign="top">
<td><tt>H</tt></td>
<td>
<p></p>Quadratic part of the objective function.<p>
	    		Class: <tt>double</tt></p>
<p>
	    		Default: []</p>
</td>
</tr>
<tr valign="top">
<td><tt>f</tt></td>
<td>
<p></p>Linear part of the objective function.<p>
	    		Class: <tt>double</tt></p>
</td>
</tr>
<tr valign="top">
<td><tt>pF</tt></td>
<td>
<p></p>Linear part of the objective function for parameters.<p>
	    		Class: <tt>double</tt></p>
<p>
	    		Default: []</p>
</td>
</tr>
<tr valign="top">
<td><tt>Y</tt></td>
<td>
<p></p>Quadratic part of the objective function for parameters.<p>
	    		Class: <tt>double</tt></p>
<p>
	    		Default: 0</p>
</td>
</tr>
<tr valign="top">
<td><tt>C</tt></td>
<td>
<p></p>Linear part of the objective function for parameters.<p>
	    		Class: <tt>double</tt></p>
<p>
	    		Default: 0</p>
</td>
</tr>
<tr valign="top">
<td><tt>c</tt></td>
<td>
<p></p>Constant term in the objective function<p>
	    		Class: <tt>double</tt></p>
<p>
	    		Default: 0</p>
</td>
</tr>
<tr valign="top">
<td><tt>A</tt></td>
<td>
<p></p>Linear part of the inequality constraints <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt16.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt16.png">.<p>
	    		Class: <tt>double</tt></p>
</td>
</tr>
<tr valign="top">
<td><tt>b</tt></td>
<td>
<p></p>Right hand side of the inequality constraints <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt17.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt17.png">.<p>
	    		Class: <tt>double</tt></p>
</td>
</tr>
<tr valign="top">
<td><tt>pB</tt></td>
<td>
<p></p>Right hand side of the inequality constraints for parameters <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt18.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt18.png">.<p>
	    		Class: <tt>double</tt></p>
</td>
</tr>
<tr valign="top">
<td><tt>Ae</tt></td>
<td>
<p></p>Linear part of the equality constraints <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt19.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt19.png">.<p>
	    		Class: <tt>double</tt></p>
<p>
	    		Default: []</p>
</td>
</tr>
<tr valign="top">
<td><tt>be</tt></td>
<td>
<p></p>Right hand side of the equality constraints <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt20.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt20.png">.<p>
	    		Class: <tt>double</tt></p>
<p>
	    		Default: []</p>
</td>
</tr>
<tr valign="top">
<td><tt>pE</tt></td>
<td>
<p></p>Right hand side of the equality constraints for parameters <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt21.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt21.png">.<p>
	    		Class: <tt>double</tt></p>
<p>
	    		Default: []</p>
</td>
</tr>
<tr valign="top">
<td><tt>lb</tt></td>
<td>
<p></p>Lower bound for the decision variables <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt22.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt22.png">.<p>
	    		Class: <tt>double</tt></p>
<p>
	    		Default: []</p>
</td>
</tr>
<tr valign="top">
<td><tt>ub</tt></td>
<td>
<p></p>Upper bound for the decision variables <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt23.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt23.png">.<p>
	    		Class: <tt>double</tt></p>
<p>
	    		Default: []</p>
</td>
</tr>
<tr valign="top">
<td><tt>Ath</tt></td>
<td>
<p></p>Linear part of the inequality constraints <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt24.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt24.png">.<p>
	    		Class: <tt>double</tt></p>
<p>
	    		Default: []</p>
</td>
</tr>
<tr valign="top">
<td><tt>bth</tt></td>
<td>
<p></p>Right hand side of the inequality constraints <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt25.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt25.png">.<p>
	    		Class: <tt>double</tt></p>
<p>
	    		Default: []</p>
</td>
</tr>
<tr valign="top">
<td><tt>vartype</tt></td>
<td>
<p></p>A vector of strings determining the type of the variable.
            Supported characters are C (continuous), I (integer), B (binary), N (semi-integer), S (semi-continuous). 
            Example: First variable from three is binary, the rest is continuous: <tt>vartype='BCC';</tt> 
        
      <p>
	    		Class: <tt>char</tt></p>
<p>
	    		Default: ''</p>
</td>
</tr>
<tr valign="top">
<td><tt>solver</tt></td>
<td>
<p></p>S string specifying which solver should be called.<p>
	    		Class: <tt>char</tt></p>
<p>
	    		Default: []</p>
</td>
</tr>
<tr valign="top">
<td><tt>M</tt></td>
<td>
<p></p>Linear matrix involved in LCP.<p>
	    		Class: <tt>double</tt></p>
<p>
	    		Default: []</p>
</td>
</tr>
<tr valign="top">
<td><tt>q</tt></td>
<td>
<p></p>Right hand side vector involved in LCP.<p>
	    		Class: <tt>double</tt></p>
<p>
	    		Default: []</p>
</td>
</tr>
<tr valign="top">
<td><tt>Q</tt></td>
<td>
<p></p>Linear matrix involved in parametric formulation of LCP.<p>
	    		Class: <tt>double</tt></p>
<p>
	    		Default: []</p>
</td>
</tr>
<tr valign="top">
<td><tt>Matrices</tt></td>
<td>
<p></p> Structure with the matrices defining MPLP/MPQP problem as returned by <tt>mpt_constructMatrices</tt> function. 
        For detailed description, see <tt>help mpt_constructMatrices</tt>.<p>
	    		Class: <tt>struct</tt></p>
</td>
</tr>
<tr valign="top">
<td><tt>constraints</tt></td>
<td>
<p></p> Yalmip set of constraints that formulate the given problem. <p>
	    		Class: <tt>lmi</tt></p>
</td>
</tr>
<tr valign="top">
<td><tt>objective</tt></td>
<td>
<p></p> Yalmip variable that represents objective value of the given problem. <p>
	    		Class: <tt>sdpvar</tt></p>
</td>
</tr>
<tr valign="top">
<td><tt>theta</tt></td>
<td>
<p></p> Specification of parametric variables involved in problem formulated in Yalmip.<p>
	    		Class: <tt>sdpvar</tt></p>
</td>
</tr>
<tr valign="top">
<td><tt>x</tt></td>
<td>
<p></p> Specification of decision variables involved in problem formulated in Yalmip.<p>
	    		Class: <tt>sdpvar</tt></p>
</td>
</tr>
</tbody>
</table>
<h2>Output Arguments</h2>
<table cellspacing="0" class="body" cellpadding="4" border="0" width="100%">
<colgroup>
<col width="31%">
<col width="69%">
</colgroup>
<tbody><tr valign="top">
<td><tt>problem</tt></td>
<td>
<p></p> Object of the <tt>Opt</tt> class that defines the optimization problem. <p>
	    		Class: <tt>Opt</tt></p>
</td>
</tr></tbody>
</table>
<h2>Example(s)</h2>
<h3>Example 
				1</h3> Formulate LP problem <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt26.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt26.png">. <pre class="programlisting"> f = [1 2 3]; A = randn(8,3); b = ones(8,1); </pre>
<pre class="programlisting"></pre> Consruct the object<pre class="programlisting"> problem = Opt('f',f,'A',A,'b',b) </pre>
<pre class="programlisting">-------------------------------------------------
Linear program
	Num variables:                3
	Num inequality constraints:   8
	Num equality constraints:     0
	Solver:                     LCP
-------------------------------------------------
</pre> Solve the problem <pre class="programlisting"> problem.solve </pre>
<pre class="programlisting">
ans = 

        xopt: [3x1 double]
      lambda: [1x1 struct]
         obj: -2.25934252307113
         how: 'ok'
    exitflag: 1

</pre>
<h3>Example 
				2</h3> Formulate MPQP <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt27.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt27.png">. <pre class="programlisting"> f = [-1 2 -3 4]; A = randn(12,4); b = ones(12,1); B = randn(12,2);  </pre>
<pre class="programlisting"></pre> Restrict the parameters to a unitbox of the size 5. <pre class="programlisting"> Ath = [eye(2); -eye(2)]; bth = 5*ones(4,1); </pre>
<pre class="programlisting"></pre> Construct the object <pre class="programlisting"> problem = Opt('H',eye(4),'f',f,'A',A,'b',b,'pB',B,'Ath',Ath,'bth',bth) </pre>
<pre class="programlisting">-------------------------------------------------
Parametric quadratic program
	Num variables:                4
	Num inequality constraints:  12
	Num equality constraints:     0
	Num parameters:               2
	Solver:                     PLCP
-------------------------------------------------
</pre> Solve the problem <pre class="programlisting"> solution = problem.solve </pre>
<pre class="programlisting">regions:   27, unexplored: 9 
mpt_plcp: 43 regions
Fixing the adjacency list...
...done.

solution = 

        xopt: [1x1 PolyUnion]
    exitflag: 1
         how: 'ok'
       stats: [1x1 struct]

</pre> Since we have an explicit solution, we can plot the partition <pre class="programlisting"> solution.xopt.plot </pre>
<pre class="programlisting"></pre>
<p class="programlistingindent"><img src="../../../../../fig/mpt/modules/solvers/@Opt/opt_img_1.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt_img_1.png" width="60%"></p>
<h3>Example 
				3</h3> Formulate LCP problem <pre class="programlisting"> H = randn(5); M = sqrt(2)*H'*H; q = randn(5,1); </pre>
<pre class="programlisting"></pre> Construct the object <pre class="programlisting"> problem = Opt('M',M,'q',q); </pre>
<pre class="programlisting"></pre> Solve the problem <pre class="programlisting"> problem.solve </pre>
<pre class="programlisting">
ans = 

        xopt: [5x1 double]
      lambda: [5x1 double]
         obj: []
         how: 'ok'
    exitflag: 1

</pre>
<h3>Example 
				4</h3> Formulate MPC parametric problem using YALMIP  Define the model <img src="../../../../../fig/mpt/modules/solvers/@Opt/opt28.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt28.png">. <pre class="programlisting"> A = 0.7*randn(2); B = randn(2,1); </pre>
<pre class="programlisting"></pre> Define the optimization variables <pre class="programlisting"> u = sdpvar(repmat(1,1,5),repmat(1,1,5)); </pre>
<pre class="programlisting"></pre>
<pre class="programlisting"> x = sdpvar(repmat(2,1,6),repmat(1,1,6)); </pre>
<pre class="programlisting"></pre> Define the constraints and the cost function. <pre class="programlisting"> objective = []; constraints = []; </pre>
<pre class="programlisting"></pre>
<pre class="programlisting"> for k = 1:5,
                objective = objective + norm(eye(2)*x{k},2) + norm(u{k},2);
                constraints = [constraints, x{k+1} == A*x{k} + B*u{k}];                
                constraints = [constraints, -5 &lt;= u{k} &lt;= 5, -10 &lt;= x{k} &lt;= 10];
              end            
        </pre>
<pre class="programlisting"></pre> Create the object <pre class="programlisting"> problem = Opt(constraints, objective, x{1}, u{1}) </pre>
<pre class="programlisting">-------------------------------------------------
Parametric linear program
	Num variables:               15
	Num inequality constraints:  30
	Num equality constraints:    10
	Num lower bounds             15
	Num upper bounds             15
	Num parameters:               2
	Solver:                     PLCP
-------------------------------------------------
</pre> Solve the problem explicitly <pre class="programlisting"> solution = problem.solve </pre>
<pre class="programlisting">mpt_plcp: 4 regions

solution = 

        xopt: [1x1 PolyUnion]
    exitflag: 1
         how: 'ok'
       stats: [1x1 struct]

</pre> Plot the explicit solution <pre class="programlisting"> solution.xopt.plot </pre>
<pre class="programlisting"></pre>
<p class="programlistingindent"><img src="../../../../../fig/mpt/modules/solvers/@Opt/opt_img_2.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt_img_2.png" width="60%"></p>
<h3>Example 
				5</h3> Formulate MPC problem using MPT2 <pre class="programlisting"> sysStruct.A = 0.7*randn(2); </pre>
<pre class="programlisting"></pre>
<pre class="programlisting"> sysStruct.B = randn(2,1); </pre>
<pre class="programlisting"></pre>
<pre class="programlisting"> sysStruct.C = [1, -1]; </pre>
<pre class="programlisting"></pre>
<pre class="programlisting"> sysStruct.D = 0; </pre>
<pre class="programlisting"></pre>
<pre class="programlisting"> sysStruct.xmin = [-10;-10]; </pre>
<pre class="programlisting"></pre>
<pre class="programlisting"> sysStruct.xmax = [10;10]; </pre>
<pre class="programlisting"></pre>
<pre class="programlisting"> sysStruct.umin = -5; </pre>
<pre class="programlisting"></pre>
<pre class="programlisting"> sysStruct.umax = 5; </pre>
<pre class="programlisting"></pre>
<pre class="programlisting"> probStruct.Q = 2*eye(2); </pre>
<pre class="programlisting"></pre>
<pre class="programlisting"> probStruct.R = 1; </pre>
<pre class="programlisting"></pre>
<pre class="programlisting"> probStruct.subopt_lev = 0; </pre>
<pre class="programlisting"></pre>
<pre class="programlisting"> probStruct.norm = 2; </pre>
<pre class="programlisting"></pre>
<pre class="programlisting"> probStruct.N = 5; </pre>
<pre class="programlisting"></pre> Create problem data to MPQP <pre class="programlisting"> Matrices = mpt_constructMatrices(sysStruct,probStruct) </pre>
<pre class="programlisting">Function mpt_constructMatrices is obsolete and will be removed in a future MPT version.
Iteration 1...
Iteration 2...
Iteration 3...

Matrices = 

           PbndIncluded: 1
                      G: [36x5 double]
                      W: [36x1 double]
                      E: [36x2 double]
                      H: [5x5 double]
                      F: [2x5 double]
                      Y: [2x2 double]
                     Cf: [0 0 0 0 0]
                     Cx: [0 0]
                     Cc: 0
              symmetric: 0
                   bndA: [4x2 double]
                   bndb: [4x1 double]
                Pinvset: [1x1 polytope]
    constraints_reduced: 1

</pre> Construct object of the <tt>Opt</tt> class. <pre class="programlisting"> problem = Opt(Matrices) </pre>
<pre class="programlisting">-------------------------------------------------
Parametric quadratic program
	Num variables:                5
	Num inequality constraints:  36
	Num equality constraints:     0
	Num parameters:               2
	Solver:                     PLCP
-------------------------------------------------
</pre> Solve the problem <pre class="programlisting"> solution = problem.solve </pre>
<pre class="programlisting">mpt_plcp: 7 regions

solution = 

        xopt: [1x1 PolyUnion]
    exitflag: 1
         how: 'ok'
       stats: [1x1 struct]

</pre> Plot the control law over the explicit solution <pre class="programlisting"> solution.xopt.fplot('primal') </pre>
<pre class="programlisting"></pre>
<p class="programlistingindent"><img src="../../../../../fig/mpt/modules/solvers/@Opt/opt_img_3.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/opt_img_3.png" width="60%"></p>
<p></p>
<table class="nav" summary="Navigation aid" border="0" width="100%" cellpadding="0" cellspacing="0"><tr valign="top">
<td align="left" width="20">
<a href="eliminateequations.html" class="button">&#9664;</a>  </td>
<td align="left">eliminateequations</td>
<td>  </td>
<td align="right">display</td>
<td align="right" width="20"><a href="display.html" class="button">&#9654;</a></td>
</tr></table>
<br><p>©  <b>2010-2013</b>     Colin Neil Jones: EPF Lausanne,    <a href="mailto:colin.jones@epfl.ch">colin.jones@epfl.ch</a></p>
<p>©  <b>2010-2013</b>     Martin Herceg: ETH Zurich,    <a href="mailto:herceg@control.ee.ethz.ch">herceg@control.ee.ethz.ch</a></p>
</body>
</html>
